#include "OA_ArgParser.h"
#include "TestOpenAPIxx.h"

using namespace std;

#define _ARGC_(x) (sizeof(x)/sizeof(const char*))
#define _ARGC_ARGV_(x) _ARGC_(x), x

int testArgParser() {
    // 正常输入
    const char* ok_argv1[] = { "test", "-a", "-b", "bbb", "--file", "this_is_file_name" };
    const char* ok_argv2[] = { "test", "-a", "-b", "bbb", "--file", "this_is_file_name", "-I", "inc", "-I", "asdfqwer_dir" };
    const char* ok_argv3[] = { "test", "-a", "-b", "bbb", "-f", "this_is_file_name", "-cde" };
    const char* ok_argv4[] = { "test", "-a", "-b", "b_value", "-I", "inc", "-f", "file_abc", "-I", "../../", "--version", "-cd", "-w", "file1.txt", "-W", "file2.txt", "--white_list", "file3.txt"};

    // 异常输入
    const char* err_argv1[] = { "test", "-a", "-b", "bbb", "-f", "this_is_file_name", "-cdeg" };
    const char* err_argv2[] = { "test", "-b", "bbb", "-f" };
    const char* err_argv3[] = { "test" };

    OAArgParser ap;
    OpenAPIxx::Args args;
    string errorMessage;

    EQU_0_PR(ap.setArg("-a", OpenAPIxx::ARGTYPE_FLAG, true, false, "aaa_disp", ""));
    EQU_0_PR(ap.setArg("-b", OpenAPIxx::ARGTYPE_STRING, false, "b_default", "bbb_disp", "BBB"));
    EQU_0_PR(ap.setArg("-I", OpenAPIxx::ARGTYPE_STRINGS, true, ARGPARSER_EMPTY_STRS, "include dir", "DIR"));
    EQU_0_PR(ap.setMultiArg({ "-f", "--file" }, OpenAPIxx::ARGTYPE_STRING, false, "", "file name", "FILE"));
    EQU_0_PR(ap.setMultiArg({ "-v", "-V", "--version" }, OpenAPIxx::ARGTYPE_FLAG, true, false, "version", ""));
    EQU_0_PR(ap.setMultiArg({ "-w", "-W", "--white_list" }, OpenAPIxx::ARGTYPE_STRINGS, true, ARGPARSER_EMPTY_STRS, "white list", ""));
    EQU_0_PR(ap.setArg("-c", OpenAPIxx::ARGTYPE_FLAG, true, false, "ccc_disp", ""));
    EQU_0_PR(ap.setArg("-d", OpenAPIxx::ARGTYPE_FLAG, true, false, "ddd_disp", ""));
    EQU_0_PR(ap.setArg("-e", OpenAPIxx::ARGTYPE_FLAG, true, false, "eee_disp", ""));
    EQU_0_PR(ap.setArg("-g", OpenAPIxx::ARGTYPE_STRING, true, "g_default", "ggg_disp", "GGG"));

    // 异常参数
    NEQ_0_PR(ap.setArg("-g", OpenAPIxx::ARGTYPE_STRING, true, false, "ggg_disp", ""));
    NEQ_0_PR(ap.setArg("-x", OpenAPIxx::ARGTYPE_FLAG, true, "asdf", "xxx_disp", ""));

    EQU_0_PR(ap.parseArg(_ARGC_ARGV_(ok_argv1), args, errorMessage));
    EQU_0_PR(ap.parseArg(_ARGC_ARGV_(ok_argv2), args, errorMessage));
    EQU_0_PR(ap.parseArg(_ARGC_ARGV_(ok_argv3), args, errorMessage));
    EQU_0_PR(ap.parseArg(_ARGC_ARGV_(ok_argv4), args, errorMessage));
    EQU_T_PR(args["-a"].boolVal);
    EQU_T_PR(args["-b"].strVal == "b_value");
    EQU_T_PR(args["-I"].strsVal[0] == "inc");
    EQU_T_PR(args["-I"].strsVal[1] == "../../");
    EQU_T_PR(args["--file"].strVal == "file_abc");
    EQU_T_PR(args["-v"].boolVal);
    EQU_T_PR(args.hasArg("-V"));
    EQU_T_PR(args.hasArg("--version"));
    EQU_T_PR(args["-c"].boolVal);
    EQU_T_PR(args["-d"].boolVal);
    EQU_F_PR(args["-e"].boolVal);
    EQU_T_PR(args["-w"].strsVal[0] == "file1.txt");
    EQU_T_PR(args["-W"].strsVal[1] == "file2.txt");
    EQU_T_PR(args["--white_list"].strsVal[2] == "file3.txt");


    NEQ_0_PR(ap.parseArg(_ARGC_ARGV_(err_argv1), args, errorMessage));
    NEQ_0_PR(ap.parseArg(_ARGC_ARGV_(err_argv2), args, errorMessage));
    NEQ_0_PR(ap.parseArg(_ARGC_ARGV_(err_argv3), args, errorMessage));

    return 0;
}
